﻿package  {
	
	import flash.geom.Vector3D;
	import ObjectDraw;
	
	/**
		A class that stores all dimensional and colour information of the 3D shape to be drawn and rotated.
		
		Although it does require the need for a few more access methods, it creates a better seperation of concerns than
		was implemented before.
	*/
	
	public class ShapeModel {
		
		// the dimensional properties of the shape
		public static const NUM_VERTICES:int = 8;
		public static const NUM_FACES:int = 6;
		public static const PERSPECTIVE_DISTORTION:Number = 400;
		public static const DEFAULT_SIZE:Number = 50;
		
		private var shapeSize:int;
		private var vertices:Vector.<Vector3D>;
		private var rotatedVertices:Vector.<Vector3D>;
		private var faces:Vector.<Array>;
		
		// face and line colours of the shape
		public static const DEFAULT_FACE_COLOURS = [0xDCE4D2,0xB8D49A,0x628141,0x335D7E,0x93BEDF,0x325B91];
		public static const DEFAULT_LINE_COLOUR = 0x000000;
		public static const DEFAULT_LINE_ALPHA = 0.1;
		public static const DEFAULT_FACE_ALPHA = 0.4;
		
		// ======
		
		public function ShapeModel(shapeSize:int = DEFAULT_SIZE) { // future args: num vertices
		
			if(shapeSize < 0) {
				shapeSize = DEFAULT_SIZE;
			}
			this.shapeSize = shapeSize;
			
			vertices = new Vector.<Vector3D>();
			rotatedVertices = new Vector.<Vector3D>();
			
			faces = new Vector.<Array>();
			
			setVertices();
			setFaces();
			
		}
		
		/**
			These methods will eventually be superseded so that an arbitrary number of vertices
			can be generated.
		*/
		
		private function setFaces():void {
			faces[0] = [0,4,5,1];
			faces[1] = [1,5,6,2];
			faces[2] = [2,6,7,3];
			faces[3] = [3,7,4,0];
			faces[4] = [4,5,6,7];
			faces[5] = [0,1,2,3];
		}
		
		private function setVertices():void {
			vertices[0] = new Vector3D(-shapeSize, -shapeSize, -shapeSize);
			vertices[1] = new Vector3D( shapeSize, -shapeSize, -shapeSize);
			vertices[2] = new Vector3D( shapeSize, -shapeSize,  shapeSize);
			vertices[3] = new Vector3D(-shapeSize, -shapeSize,  shapeSize);
			vertices[4] = new Vector3D(-shapeSize,  shapeSize, -shapeSize);
			vertices[5] = new Vector3D( shapeSize,  shapeSize, -shapeSize);
			vertices[6] = new Vector3D( shapeSize,  shapeSize,  shapeSize);
			vertices[7] = new Vector3D(-shapeSize,  shapeSize,  shapeSize);
			
			rotatedVertices[0] = new Vector3D(0, 0, 0);
			rotatedVertices[1] = new Vector3D(0, 0, 0);
			rotatedVertices[2] = new Vector3D(0, 0, 0);
			rotatedVertices[3] = new Vector3D(0, 0, 0);
			rotatedVertices[4] = new Vector3D(0, 0, 0);
			rotatedVertices[5] = new Vector3D(0, 0, 0);
			rotatedVertices[6] = new Vector3D(0, 0, 0);
			rotatedVertices[7] = new Vector3D(0, 0, 0);
		}
		
		// accessor methods
		
		public function setRotatedVertices(rotatedVertices:Vector.<Vector3D>):void {
			this.rotatedVertices = rotatedVertices;
		}
		
		public function getRotatedVertices():Vector.<Vector3D> {
			return rotatedVertices;
		}
		
		public function getVertices():Vector.<Vector3D> {
			return vertices;
		}
		
		public function getFaces():Vector.<Array> {
			return faces;
		}
		
		public function getNumFaces():int {
			return NUM_FACES;
		}
		
		public function getNumVertices():int {
			return NUM_VERTICES;
		}
		
		public function getLineColour():uint {
			return DEFAULT_LINE_COLOUR;
		}
		
		public function getLineAlpha():Number {
			return DEFAULT_LINE_ALPHA;
		}
		
		public function getFaceAlpha():Number {
			return DEFAULT_FACE_ALPHA;
		}
		
		public function getFaceColours(index:uint):uint {
			return DEFAULT_FACE_COLOURS[index];
		}
		
		public function getPerspectiveDistortion():uint {
			return PERSPECTIVE_DISTORTION;	
		}
	}
	

	
}
